#include "../../head/utils/SendSerialUtil.h"
#include <QtDebug>

#include <QThread>
#include<QtSerialPort/QSerialPort>      //串口功能头文件
#include<QByteArray>
#include<QTimer>
#include<QString>
#include<QMessageBox>
#include<QCoreApplication>
#include "../../head/utils/DemoduleUtil.h"


//QList<double> list1;
//QList<double> list;
extern DemoduleUtil *demoduleUtil;


SendSerialUtil::SendSerialUtil(QObject *parent):QObject(parent)
{

    //设置串口属性
    sendSerialPort = new QSerialPort(this);
//    sendSerialPort->setReadBufferSize(512);
//    sendSerialPort->setPortName(port);
//    sendSerialPort->setBaudRate(baudRate);
//    sendSerialPort->setDataBits(dataBits);
//    sendSerialPort->setStopBits(stopBits);
//    sendSerialPort->setParity(checkBits);
    //sendSerialPort->setFlowControl(QSerialPort::NoFlowControl);


//    connect(sendSerialPort,&QSerialPort::readyRead,
//    [=]()
//    {


//    });
}

QString SendSerialUtil::connectSendSerail(){

    //触发信号
    if(sendSerialPort->open(QIODevice::WriteOnly) == true)
    {
         //qDebug() << "=======串口线程连接成功============" << endl;
         serial_Connect_State = true;
         return "true";

    }else{
      // qDebug() << "=======串口线程连接失败============" << endl;
       serial_Connect_State = false;
       return "false";
    }

}

void SendSerialUtil::sendMessage(QByteArray qb){
     sendSerialPort->write(qb);
     //qDebug()<<"SEND FINISHED"<<endl;
     demoduleUtil->record_log("SEND FINISHED");

}


void SendSerialUtil::sendMessage1(QString qb){
    sendSerialPort->write(qb.toLatin1());
}
